package com.ruoyi.web.controller.crudinterface;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.mapper.CommonMapper;
import com.ruoyi.common.utils.crudinterface.vo.ReqVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@Api(tags = "调用接口操作增删改查（免登录）")
@RestController
@RequestMapping("/webs/dbInterface")
public class DBController extends BaseController
{

    @Resource
    private CommonMapper commonMapper;


    @ApiOperation("获取单个对象")
    @PostMapping("/getBean")
    public AjaxResult getBean(@Validated @RequestBody final ReqVo reqVo)
    {
        return AjaxResult.success(commonMapper.selectOneBySql(reqVo.getSql()));
    }

    @ApiOperation("获取List")
    @PostMapping("/getList")
    public AjaxResult getList(@Validated @RequestBody final ReqVo reqVo)
    {
        return AjaxResult.success(commonMapper.selectListBySql(reqVo.getSql()));
    }

    @ApiOperation("创建")
    @PostMapping("/create")
    public AjaxResult create(@Validated @RequestBody final ReqVo reqVo)
    {
        return AjaxResult.success(commonMapper.executeSql(reqVo.getSql()));
    }

    @ApiOperation("更新")
    @PostMapping("/update")
    public AjaxResult update(@Validated @RequestBody final ReqVo reqVo)
    {
        return AjaxResult.success(commonMapper.executeSql(reqVo.getSql()));
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public AjaxResult delete(@Validated @RequestBody final ReqVo reqVo)
    {
        return AjaxResult.success(commonMapper.executeSql(reqVo.getSql()));
    }




}
